package com.yd.mvc.mobile.gStyleController;

import com.yd.app.service.mobile.gStyleService.MGStyleService;
import com.yd.app.util.BusinessException;
import com.yd.domain.business.GStyle;
import com.yd.mvc.baseController.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品样式
 * Created by sunxianhui on 2018/3/12.
 */
@RestController
@RequestMapping(value = "/dapi/mgStyle")
public class MGStyleController extends BaseController {
    @Autowired
    MGStyleService mGStyleService;

    /**
     * 添加
     * @param gStyle
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public GStyle addGStyle(@RequestBody GStyle gStyle) throws BusinessException {

        int count= mGStyleService.addGStyle(gStyle);
        if(count==1){
            return gStyle;
        }else {
            throw new BusinessException(500, "添加产品样式信息失败");
        }
    }

    /**
     * 修改
     * @param gStyle
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public void updateGStyle(@RequestBody GStyle gStyle) {
        mGStyleService.updateGStyle(gStyle);
    }

    /**
     * 删除
     * @param id
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public void deleteGStyle(@PathVariable("id") String id) {
        mGStyleService.deleteGStyleByid(id);
    }


    /**
     * 查询产品样式列表
     * @return
     * @throws BusinessException
     */
    @RequestMapping(value = "/getGStyleList", method = RequestMethod.GET)
    public List<GStyle> getGStyleList() throws BusinessException {
        List<GStyle> list = null;
        try {
            list = mGStyleService.getGStyleList();
        } catch (Exception e) {
            throw new BusinessException(500, "获取产品样式信息失败");
        }
        return list;
    }
}
